/*
 * Copyright 2011 Marcos Fabio Pereira
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package com.moveme.network.payload.state;

import java.nio.ByteBuffer;

import com.moveme.network.payload.PSPayload;
import com.moveme.network.payload.PayloadConstants;

/**
 * State payload type. This class is used to represent both standard states and
 * camera frame states.
 * 
 * In order to know what kind of state is it, check the 'header' attribute.
 * 
 * @author Marcos Fabio Pereira
 * 
 */
public class PSMoveState extends PSPayload {

    /**
     * Server config
     */
    public PSMoveServerConfig serverConfig;

    /**
     * Move status, one for each move (0..3)
     */
    public PSMoveStatus[] moveStatus;

    /**
     * Gem state, one for each move (0..3)
     */
    public PSMoveGemState[] moveGemState;

    /**
     * Image state, one for each move (0..3)
     */
    public PSMoveImageState[] moveImageState;

    /**
     * Pointer state, one for each move (0..3)
     */
    public PSMovePointerState[] movePointerState;

    /**
     * Pointer sphere state, one for each move (0..3)
     */
    public PSMoveSphereState[] moveSphereState;

    /**
     * Pointer position state, one for each move (0..3)
     */
    public PSMovePositionPointerState[] movePositionPointerState;

    /**
     * Move navigation data, one for each controller (0..6)
     */
    public PSMoveNavPadData[] moveNavPadData;

    /**
     * Move navigation data info, one for each controller (0..6)
     */
    public PSMoveNavPadInfo[] moveNavPadInfo;

    @Override
    public void processBody(ByteBuffer byteBuffer) {
        serverConfig = new PSMoveServerConfig(byteBuffer);

        moveStatus = new PSMoveStatus[PayloadConstants.PSMOVE_SERVER_MAX_CONS];
        moveGemState = new PSMoveGemState[PayloadConstants.PSMOVE_SERVER_MAX_CONS];
        moveImageState = new PSMoveImageState[PayloadConstants.PSMOVE_SERVER_MAX_CONS];
        movePointerState = new PSMovePointerState[PayloadConstants.PSMOVE_SERVER_MAX_CONS];
        moveSphereState = new PSMoveSphereState[PayloadConstants.PSMOVE_SERVER_MAX_CONS];
        movePositionPointerState = new PSMovePositionPointerState[PayloadConstants.PSMOVE_SERVER_MAX_CONS];

        for (short i = 0; i < PayloadConstants.PSMOVE_SERVER_MAX_CONS; i++) {
            moveStatus[i] = new PSMoveStatus(byteBuffer, i);
            moveGemState[i] = new PSMoveGemState(byteBuffer, i);
            moveImageState[i] = new PSMoveImageState(byteBuffer, i);
            movePointerState[i] = new PSMovePointerState(byteBuffer, i);
            moveSphereState[i] = new PSMoveSphereState(byteBuffer, i);
            movePositionPointerState[i] = new PSMovePositionPointerState(
                    byteBuffer, i);
        }

        moveNavPadData = new PSMoveNavPadData[PayloadConstants.PSMOVE_SERVER_MAX_NAVS];
        moveNavPadInfo = new PSMoveNavPadInfo[PayloadConstants.PSMOVE_SERVER_MAX_NAVS];

        for (short i = 0; i < PayloadConstants.PSMOVE_SERVER_MAX_NAVS; i++) {
            moveNavPadInfo[i] = new PSMoveNavPadInfo(byteBuffer, i);
            moveNavPadData[i] = new PSMoveNavPadData(byteBuffer, i);
        }
    }
}